const uploadUtils=require('./uploadUtils')
const path = require('path')
const config=require('../api/config')
const qiniuConfig=config.qiniuConfig



exports.uploadImage= async (ctx, next) => {
    const serverPath = path.join(__dirname, '../public/uploads/')

    const result = await uploadUtils.uploadFile(ctx, {
        fileType: 'qiniu',
        path: serverPath
    })

    const imgPath = path.join(serverPath, result.imgPath)

    const qiniu = await uploadUtils.upToQiniu(imgPath, result.imgKey)


    return {
       url:`${qiniuConfig.url}${qiniu.key}`,
       thumbnail:`${qiniuConfig.url}${qiniu.key}?imageView2/1/w/100/h/100/q/75|imageslim`
    }
}



exports.uploadToken= async (filename) => {
    let res=await uploadUtils.upToQiniuToken(filename)

    return  res

}



//建伟上传图片到七牛
exports.uploadTokenForXuesheng= async (filename) => {
    let res=await uploadUtils.upToQiniuTokenForXuesheng(filename)

    return  res

}
